<template>
	<el-dialog v-model="visible" title="项目周进度上报" close-on-click-modal @close="closeHandle">
		<el-form
			ref="dataFormRef"
			v-loading="loading"
			:model="dataForm"
			:rules="dataRules"
			label-position="top"
			label-suffix="："
			@keyup.enter="submitHandle()"
		>
			<el-form-item label="本周进度" prop="weeklyProgress">
				<el-input v-model="dataForm.weeklyProgress" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取消</el-button>
			<el-button type="primary" :disabled="loading" @click="submitHandle()">确定</el-button>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus/es'
import { updateReport } from '@/api/project/report'

const emit = defineEmits(['refreshDataList'])
const loading = ref(false)
const visible = ref(false)
const dataFormRef = ref()

const dataForm = reactive({
	projectId: '',
	weeklyProgress: ''
})

const open = (id?: number) => {
	visible.value = true
	if (dataFormRef.value) {
		dataFormRef.value.resetFields()
	}
	dataForm.projectId = id
}
const closeHandle = () => {
	visible.value = false
}
// const getInfo = (id: number) => {
// 	loading.value = true
// 	useInfoApi(id)
// 		.then(res => {
// 			Object.assign(dataForm, res.data)
// 			dataForm.id = id
// 		})
// 		.finally(() => {
// 			loading.value = false
// 		})
// }

const dataRules = ref({
	weeklyProgress: [{ required: true, message: '必填信息', trigger: 'blur' }]
})

// 表单提交
const submitHandle = () => {
	dataFormRef.value.validate((valid: boolean) => {
		if (!valid) {
			return false
		}
		loading.value = true
		updateReport(dataForm)
			.then(() => {
				ElMessage.success({
					message: '操作成功',
					duration: 500,
					onClose: () => {
						visible.value = false
						emit('refreshDataList')
					}
				})
			})
			.finally(() => {
				dataFormRef.value.resetFields()
				loading.value = false
			})
	})
}

defineExpose({
	open
})
</script>
<style scoped lang="scss">
:deep(.el-input-number) {
	min-width: 35%;
}
</style>
